<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>

	<link rel="stylesheet" href="Public/Bootstrap/Css/bootstrap.min.css" />
	<link rel="stylesheet" href="Public/css.css" />
	<link rel="stylesheet" href="Public/Uploadify/uploadify.css" />
	<!--载入百度编辑器-->
	    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	<!--<script type="text/javascript" src='__PUBLIC__/Js/jquery-1.7.2.min.js'></script>-->
	<script type="text/javascript" src='Public/Uploadify/jquery.uploadify.js'></script>
	<script type="text/javascript" src='__ROOT__/Public/Ueditor/ueditor.config.js'></script>
	<script type="text/javascript" src='__ROOT__/Public/Ueditor/ueditor.all.min.js'></script>
	<script type="text/javascript" src='__PUBLIC__/Js/goods.js'></script>
	<script type="text/javascript" src="Public/js/jquery-1.8.2.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$('[name=class_cid]').change(function(){
				var tid = $('option:selected').attr('tid');
				$('[name=nature_nid]').attr('value',tid)
				$.ajax({
					type:"post",
					url:"{{U('Goods/getTypeAttr')}}",
					data:{id : tid},
					dataType:'json',
					success:function(phpData){
						//规格(可选)
						var spec = '';
						//属性（不可选）
						var attr = '';
						$.each(phpData, function(k,v) {    
							//规格
							if(v.natype == 0){
								spec += '<tr class="info">' +
								'<td>'+v.naname+'</td>' +
								'<td>' +
									'<select name="spec['+v.nid+'][value][]" id=""><option value="">请选择</option>';
										$.each(v.nazhi, function(kk,vv) {    
											 spec += '<option value="'+vv+'">'+vv+'</option>';                                                      
										});
									spec += '</select></td><td>附加价格：<input type="text" name="spec['+v.nid+'][addition][]" id="" /></td>' +
										'<td><span class="btn btn-success add-spec">增加规格</span></td></tr>';
							
							}else{//属性
								attr += '<tr class="info">' + 
											'<td>'+v.naname+'</td>' + 
											'<td>' + 
											'<select name="attr['+v.nid+']" id=""><option value="">请选择</option>';
												
												$.each(v.nazhi, function(kk,vv) {    
													 attr += '<option value="'+vv+'">'+vv+'</option>';                                                      
												});
												
								attr += '</select></td></tr>';
							}                                                          
						});
						
						//插入属性
						$('#attr').html(attr);
						$('#spec').html(spec);
					}
				});
			})
	
	
			//点击添加规格
			$('.add-spec').live('click',function(){
				//找到父级的tr
				var parentsTr = $(this).parents('tr');
				//把父级的tr克隆复制
				var cloneTr = parentsTr.clone();
				cloneTr.find('.add-spec').removeClass('add-spec btn-success').addClass('remove-spec btn-danger').html('删除规格');
				//插入下一行
				parentsTr.after(cloneTr);
			})
			//删除规格
			$('.remove-spec').live('click',function(){
				$(this).parents('tr').remove();
			})
		})
		
	</script>
	<style type="text/css">
		/*去掉uploadify上传按钮的边框*/
	    .uploadify-button {
	        background-color: transparent;
	        border: none;
	        padding: 0;
	    }
	    .uploadify:hover .uploadify-button {
	        background-color: transparent;
    	}
    	.hide{
    		display: none;
    	}
    	body{
    		margin-bottom: 100px;
    	}
	</style> 
	<script type="text/javascript">
		var root = '__ROOT__';
		//图片上传提交地址
		var handler = '{:U("uploadEditor")}';
		var uploadify_path = '__UPLOADIFY__';
		var sess_name = "<?php echo session_name(); ?>";
		var sess_id = "<?php echo session_id(); ?>";
		//列表图上传地址
		var pic_uploader = '{:U("uploadPic")}';
		//商品图册上传地址
		var photo_uploader = '{:U("uploadPhoto")}';
		var upload_path = '__UPLOAD__';
		var delPic = '{:U("delPic")}';
		var getAttr = '{:U("getAttr")}';
	</script>
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">

	<form action="" method='post' enctype="multipart/form-data">
		<fieldset>
			<legend>修改商品</legend>
			<table class='table table-bordered table-hover'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="class_cid">
								<option value="">请选择</option>
								{{foreach from="$cateData" value="$v"}}
								<option value="{{$v['cid']}}" type_tid="{{$v['type_tid']}}" {{if value="$v['cid']==$oldData['class_cid']"}}selected{{endif}}>{{$v['_name']}}</option>
								{{endforeach}}
								
							</select>
							<input type="hidden" name="nature_nid" value=""/>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="brand_bid">
								<option value="">请选择</option>
								{{foreach from="$brandData" value="$v"}}
								<option value="{{$v['bid']}}" brand_bid="$v['brand_bid']" {{if value="$v['bid']==$oldData['brand_bid']"}}selected{{endif}}>{{$v['bname']}}</option>
								{{endforeach}}
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname' value="{{$oldData['gname']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>数量</td>
						<td>
							<input type="text" name='gnum' value="{{$oldData['gnum']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>总库存</td>
						<td>
							<input type="text" name='store' value="{{$oldData['store']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='unit' value="{{$oldData['unit']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='gshi' value="{{$oldData['gshi']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='gshang' value="{{$oldData['gshang']}}"/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='click' value="{{$oldData['click']}}"/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
				
					{{foreach from="$attr2" value="$v" }}
					{{if value="$v['natype']  eq 0 "}}
					<tr class="info">
						<td>{{$v['naname']}}</td>
						<td>
							<select name="attr[{{$v['nid']}}]">
								<option value="0">请选择</option>
								{{foreach from="$v['nazhi']" value="$vv" }}
								<option value="{{$vv}}" {{if value="$v['sxzhi'] eq $vv"}}selected{{endif}} >{{$vv}}</option>
								{{endforeach}}
							</select>
						</td>
					</tr>
					{{endif}}
					{{endforeach}}
				
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
				
					{{foreach from="$attr2" value="$v" }}
					{{if value="$v['natype']  eq 1 "}}
					<tr class="info">
						<td>{{$v['naname']}}</td>
						<td>
							<select name="spec[{{$v['nid']}}][value][]">
								<option value="0">请选择</option>
								{{foreach from="$v['nazhi']" value="$vv"}}
								<option value="{{$vv}}" {{if value="$v['sxzhi'] eq $vv" }}selected{{endif}}>{{$vv}}</option>
								{{endforeach}}
							</select>
							<td>附加价格：<input type="text" name="spec[{{$v['nid']}}][price][]" id="" value="{{$v['addition']}}"/></td>
						</td>
						
					</tr>
					{{endif}}
					{{endforeach}}
				
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<img src="{{$oldData['listtu']}}"/>
						<input type="hidden" name="listtu" value="{{$oldData['listtu']}}" />
						<!--<input type="file" name='listtu' id='pic'/>-->
					</td>
					<td id='pic-list'></td>
				</tr>
			</table>

			<!--<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<img src="{{$detail['picture']}}"/>
						<input type="hidden" name="picture" value="{{$detail['picture']}}" />
					</td>
					<td id='photo-list'></td>
				</tr>
			</table>-->

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">商品详细</th>
				</tr>
				<tr>

			<!--调用百度编辑器-->
			<script id="editor" type="text/plain" style="width:100%;height:200px;" name="aoodsxx">
			{{$detail[0]['aoodsxx']}}
			</script>
		    <script>
		        var ue = UE.getEditor('editor');
		    </script>
				
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">售后服务</th>
				</tr>
				<tr>

			<!--调用百度编辑器-->
			<script id="editor1" type="text/plain" style="width:100%;height:200px;" name="sale">{{$detail[0]['sale']}}</script>
		    <script>
		        var ue = UE.getEditor('editor1');
		    </script>
				
				</tr>
			</table>
			<input type="hidden" name='tid' value='0'/>
			<input type="submit" value="确认修改" class="btn btn-primary btn-block btn-large" />
		</fieldset>
	</form>

	</div>
	</div>
	</div>
</body>
</html>